package web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.NoticeDao;
import dao.NoticeDaoFactory;

/*
 * 作用：删除多条数据
 */

@WebServlet("/DeteleNoticesServlet")
public class DeteleNoticesServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//1.获取客户端传递过的参数
		String[] cb = request.getParameterValues("cb");
		PrintWriter out = response.getWriter();
		if (cb==null){
			out.print("false");
		}
		else{
			//2.调用service（dao）删除，接收返回结果
			NoticeDao dao = new NoticeDaoFactory().factory();
			boolean flag = dao.deleteByIds(cb);
			//3.根据结果，输出一个成功的标志(跳转留到jquery的成功事件来写)
			if (flag){
				out.print("true");
			}else{
				out.print("false");
			}
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
